package com.ruoyi.business.controller;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.utils.DateUtils;
import com.github.pagehelper.util.StringUtil;
import com.ruoyi.business.domain.ZrsMbManageZb;
import com.ruoyi.business.service.IZrsMbManageZbService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 责任书模版指标关系Controller
 * 
 * @author Yuhf
 * @date 2023-11-18
 */
@RestController
@RequestMapping("/business/ZrsMbManageZb")
public class ZrsMbManageZbController extends BaseController
{
    @Autowired
    private IZrsMbManageZbService zrsMbManageZbService;

    /**
     * 查询责任书模版指标关系列表
     */
    @PreAuthorize("@ss.hasPermi('business:ZrsMbManageZb:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZrsMbManageZb zrsMbManageZb)
    {
        startPage();
        List<ZrsMbManageZb> list = zrsMbManageZbService.selectZrsMbManageZbList(zrsMbManageZb);
        return getDataTable(list);
    }

    /**
     * 导出责任书模版指标关系列表
     */
    @PreAuthorize("@ss.hasPermi('business:ZrsMbManageZb:export')")
    @Log(title = "责任书模版指标关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZrsMbManageZb zrsMbManageZb)
    {
        List<ZrsMbManageZb> list = zrsMbManageZbService.selectZrsMbManageZbList(zrsMbManageZb);
        ExcelUtil<ZrsMbManageZb> util = new ExcelUtil<ZrsMbManageZb>(ZrsMbManageZb.class);
        util.exportExcel(response, list, "责任书模版指标关系数据");
    }

    /**
     * 获取责任书模版指标关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:ZrsMbManageZb:query')")
    @GetMapping(value = "/{zrszbId}")
    public AjaxResult getInfo(@PathVariable("zrszbId") Long zrszbId)
    {
        return success(zrsMbManageZbService.selectZrsMbManageZbByZrszbId(zrszbId));
    }

    /**
     * 新增责任书模版指标关系
     */
    @PreAuthorize("@ss.hasPermi('business:ZrsMbManageZb:add')")
    @Log(title = "责任书模版指标关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZrsMbManageZb zrsMbManageZb)
    {
    	zrsMbManageZb.setCreateTime(DateUtils.getNowDate());
    	zrsMbManageZb.setCreateBy(getUsername());
        return toAjax(zrsMbManageZbService.insertZrsMbManageZb(zrsMbManageZb));
    }

    /**
     * 修改责任书模版指标关系
     */
    @PreAuthorize("@ss.hasPermi('business:ZrsMbManageZb:edit')")
    @Log(title = "责任书模版指标关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZrsMbManageZb zrsMbManageZb)
    {
    	
    	zrsMbManageZb.setUpdateTime(DateUtils.getNowDate());
    	zrsMbManageZb.setUpdateBy(getUsername());
        return toAjax(zrsMbManageZbService.updateZrsMbManageZb(zrsMbManageZb));
    }
    /**
     * 修改责任书模版指标关系
     */
    @PreAuthorize("@ss.hasPermi('business:ZrsMbManageZb:edit')")
    @Log(title = "责任书模版指标关系--修改模版指标", businessType = BusinessType.UPDATE)
    @PostMapping("/updateMbZbmanage")
    public AjaxResult updateMbZbmanage(@RequestBody ZrsMbManageZb zrsMbManageZb)
    {
    	
    	zrsMbManageZb.setUpdateTime(DateUtils.getNowDate());
    	zrsMbManageZb.setUpdateBy(getUsername());
        return toAjax(zrsMbManageZbService.updateZrsMbManageZb(zrsMbManageZb));
    }
    /**
     * 修改责任书模版指标关系
     */
    @PreAuthorize("@ss.hasPermi('business:ZrsMbManageZb:edit')")
    @Log(title = "责任书模版指标关系--添加模版指标", businessType = BusinessType.UPDATE)
    @PostMapping("/addMbZbmanage")
    public AjaxResult addMbZbmanage(@RequestBody ZrsMbManageZb zrsMbManageZb)
    {
    	
    	zrsMbManageZb.setUpdateTime(DateUtils.getNowDate());
    	zrsMbManageZb.setUpdateBy(getUsername());
        return toAjax(zrsMbManageZbService.insertZrsMbManageZb(zrsMbManageZb));
    }
    
    
    /**
     * 修改责任书模版指标关系
     */
    @PreAuthorize("@ss.hasPermi('business:ZrsMbManageZb:edit')")
    @Log(title = "责任书模版指标--考核周期和审核部门", businessType = BusinessType.UPDATE)
    @PostMapping("/editZrsMbManageZb")
    public AjaxResult editZrsMbManageZbToMbIdAndZbId(@RequestBody ZrsMbManageZb zrsMbManageZb)
    {
    	
    	if(zrsMbManageZb.getMbId() == null) {
    		return AjaxResult.error("传递参数不能为空！mb");
    	}
    	if(zrsMbManageZb.getZbId() == null) {
    		return AjaxResult.error("传递参数不能为空！zb");
    	}
    	if(StringUtil.isEmpty(zrsMbManageZb.getZrsZbCheckdate()) && zrsMbManageZb.getZrszbShDept() == null) {
    		return AjaxResult.error("传递参数不能为空！param");
    	}
    	
        return toAjax(zrsMbManageZbService.editZrsMbManageZbToMbIdAndZbId(zrsMbManageZb));
    }
    /**
     * 修改责任书模版指标关系
     */
    @PreAuthorize("@ss.hasPermi('business:ZrsMbManageZb:edit')")
    @Log(title = "责任书模版指标关系", businessType = BusinessType.UPDATE)
    @PostMapping("/updateZrsMbManageGoalToSaveZb")
    public AjaxResult updateZrsMbManageGoalToSaveZb(@RequestBody ZrsMbManageZb zrsMbManageZb)
    {
    	
    	zrsMbManageZb.setUpdateTime(DateUtils.getNowDate());
    	zrsMbManageZb.setUpdateBy(getUsername());
        return toAjax(zrsMbManageZbService.updateZrsMbManageGoalToSaveZb(zrsMbManageZb));
    }
    
    @PreAuthorize("@ss.hasPermi('business:ZrsMbManageZb:query')")
    @PostMapping("/getMbZbmanage")
    public AjaxResult getMbZbmanage(@RequestBody ZrsMbManageZb zrsMbManageZb)
    {
    	return AjaxResult.success(zrsMbManageZbService.selectZrsMbManageZbByMbZbId(zrsMbManageZb));
    }
}
